package com.tigercel.xiangchengyun.utils;

import android.content.Context;
import android.os.Message;
import android.provider.Settings;

import java.util.Locale;

public class Global {
    private static Global global = null;
    /**
     * 发送消息时的消息ID
     */
    private static int id = 0;
    /**
     * 当前Activity的Context环境
     */
    public static Context context = null;
    /**
     * 发送消息的hander
     */
    private static BaseHandler handler = new BaseHandler();
    public static String baseUrl = "http://develop.api.xcy.tigercel.com/";//基本网址
    public static String ImgBaseUrl = "http://tcloudapi.oss-cn-shanghai.aliyuncs.com/";//图片拼接地址
    public static String TvUrl = "v1/channel/tv/content";//电视栏目网址
    public static String TvUrlMore = "v1/channel/tv/content/page";//电视栏目更多网址
    public static String festivalUrl = "v1/channel/festival/content";//春晚网址
    public static String festivalUrlMore = "v1/channel/festival/content/page";//春晚更多网址
    public static String commonUrlMore = "v1/channel/content/page";//首页更多网址
    public static String commonUrl = "v1/channel/content";//首页网址
    public static String facilitate_info = "v1/facilitate/info";//便民详情
    public static String facilitate_upload = "v1/facilitate/upload";//上传报料
    public static String services = "v1/service/list";//服务页面数据

    private Global() {
    }

    public static void setHandler(BaseHandler handler) {
        Global.handler.removeSelf(Global.handler);
        Global.handler = handler;
        handler.addSelf(handler);
    }

    public static Global instance() {
        if (global == null) {
            global = new Global();
        }
        return global;
    }

    public static void setContext(Context cxt) {
        context = cxt;
    }

    public static String nid() {
        return String.valueOf(++id);
    }

    public static String id() {
        return String.valueOf(id);
    }

    /**
     * 获取当前的语言环境信息
     */
    public static Locale locale() {
        return context.getResources().getConfiguration().locale;
    }

    public static void sendMsg(int what, Object msg) {
        handler.sendMsg(handler.obtainMessage(what, msg));
    }

    public static void sendMsg(Message msg) {
        handler.sendProcessMsg(msg);
    }

    public static void sendMsg(int what) {
        handler.sendMsg(handler.obtainMessage(what));
    }

    public static String getDeviceId() {
        String deviceId = "";
        deviceId = Settings.System.getString(context.getContentResolver(), Settings.System.ANDROID_ID);
        return deviceId;
    }
}
